package com.hsogoo.study.spring.propertysource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * Created by za-huangsaigang on 2018/9/17.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes={ConfigPropertySourceProcessor.class, PropertySourcesPlaceholderConfigurer.class, CustomizePropertyBean.class})
public class CustomizePropertyTest {

    @Autowired
    private ApplicationContext context;

    @Test
    public void testCustomizeProperty(){
//        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext("com.hsogoo.study.spring");
        CustomizePropertyBean bean = context.getBean(CustomizePropertyBean.class);
        System.out.println(bean.getAppName());
        //为啥输出${appName}
        /**
         * environment set...
         * ConfigPropertySourceProcessor.postProcessBeanFactory() invoked...
         * CustomizePropertyTest init...
         * ${appName}
         * 原来是忘了加PropertySourcesPlaceholderConfigurer这个类了
         */
    }

}
